<template>
  <div class="topNav">
    <div class="topLeft">
      <span class="iconfont icon-31liebiao"></span>
    </div>
    <div class="topCenter" @click="changeNav" ref="navList">
      <span class="navBtn" @click="$router.push('/me')">我的</span>
      <span class="navBtn active">发现</span>
      <span class="navBtn">云村</span>
      <span class="navBtn">视频</span>
    </div>
    <div class="topRight" @click="$router.push('/search')">
      <span class="iconfont icon-sousuo"></span>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'
export default {
  name: 'TopNav',
  setup() {
    const navList = ref()
    // 切换导航
    const changeNav = e => {
      ;[...navList.value.querySelectorAll('span')].forEach(ele => {
        ele.classList.remove('active')
      })
      e.target.classList.add('active')
    }

    return {
      changeNav,
      navList
    }
  }
}
</script>

<style lang="less" scoped>
.topNav {
  width: 7.5rem;
  height: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem;
}
.topCenter {
  // 设置字体大小
  font-size: 0.4rem;
  .navBtn {
    display: inline-block;
    margin-left: 0.2rem;
    color: #999;
  }
  .active {
    font-weight: bold;
    color: #000;
  }
}
</style>